home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / AppleScript / Development Tools / Tools Goodies / AEGizmos 1.4.1 / Documentation / AEStream Doc.dp (.txt) < prev    next >
Encoding:
Common Ground  |  1995-03-20  |  27.5 KB  |  336 lines  |  [CGDC/CGVM]

  1. Palatino
  2. Apple Events
  3.  Stream Library
  4. AEGizmos Version 1.4
  5. Jens Peter Alfke
  6. 20 March 1995
  7.  Apple Computer, Inc. 1991
  8. New York
  9. Palatino
  10. The Apple Event Stream Library
  11. 20 March 1995
  12. Page 
  13. Contents
  14. Contents
  15. )7 ................................
  16. )h ................................
  17. )h ................................
  18. Introduction
  19. )M ................................
  20. )h ................................
  21. ...............................
  22. OK, What Is It?
  23. s In It For Me?
  24. Just How Stable Is It, Anyway?
  25. What Are All Those Files?
  26. Disclaimer
  27. AEStream Functions
  28. ){ ................................
  29. )h ................................
  30. .................
  31. Opening and Closing a Stream
  32. Writing Descriptors
  33. Writing Lists
  34. Writing Records
  35. #Writing Key Descriptors For Records
  36. The Header Files
  37. )g ................................
  38. )h ................................
  39. .......................
  40. AEStream.h
  41. AEStream_CPlus.h
  42. New York
  43. Palatino
  44. The Apple Event Stream Library
  45. 20 March 1995
  46. Page 
  47. Introduction
  48. OK, What Is It?
  49. LThe Apple Event Manager routines that assemble descriptors and parameters (I
  50. speak here of 
  51. Courier
  52. AECreateDesc
  53. AECreateList
  54.     AEPutDesc
  55. AEPutParamDesc
  56. et al
  57. fMprovide very flexible random access at the expense of significant overhead in
  58. Ispeed and memory. Constructing nested structures involves duplicating and
  59. Lcopying a whole lot of data. In many cases, programs create descriptors in a
  60. 6more or less linear fashion, without many common subex
  61. pressions. In such
  62. fPsituations you could use a stream-like protocol and speed things up quite a bit.
  63. MThat
  64. s what the AEStream library does for you. It doesn
  65. t use the Apple Event
  66. PManager at all. Instead, it builds up a single descriptor from beginning to end.
  67. OThe descriptor data stays all in one block and grows in discrete increments, so
  68. -there will be far fewer Memory Manager calls.
  69. s In It For Me?
  70. Zapf Dingbats
  71. ESheer, raw speed. It
  72. s about three to four times as fast as using the
  73. Apple
  74. Event Manager routines.
  75. @Code that builds nested descriptors will be simpler and clearer.
  76. CSimpler cleanup; there
  77. s only one stream object, not a multitude of
  78. descriptors, to be disposed.
  79.  How About Access From Pascal?
  80. SAs far as I know, there
  81. s no reason why you couldn
  82. t call this library from Pascal,
  83. whether the 
  84. THINK
  85. )!5 variety. All you need to do is write a Pascal header
  86. fQequivalent to AEStream.h. (Keep in mind that all the functions have use C calling
  87. Vconventions.) If you write one, send it to me and I
  88. ll include it in the next release.
  89. Palatino
  90. The Apple Event Stream Library
  91. Page 
  92. 20 March 1995
  93. AEStream Functions
  94. PENING AND 
  95.     LOSING A 
  96. TREAM
  97. AEStream_Open
  98. Courier
  99. $OSErr AEStream_Open( AEStreamRef s )
  100. AEStream_Open
  101. )N* opens the stream structure pointed to by 
  102.  as a new, empty
  103. NOstream suitable for writing a single (simple or nested) descriptor. You must do
  104. 8this before writing any data to the stream. For example:
  105. AEStream myStream;
  106. err= AEStream_Open(&myStream);
  107. // more stream calls...
  108. AEStream_OpenEvent
  109. ;OSErr AEStream_OpenEvent( AEStreamRef s, AppleEvent *aevt )
  110. AEStream_OpenEvent
  111. )l* opens the stream structure pointed to by 
  112.  for appending to
  113. the existing Apple Event 
  114. + (which was presumably created by a call to
  115. AECreateAppleEvent
  116. )l:.) You can then add parameters to the event by adding them
  117. as key descriptors (see the 
  118. Writing Key Descriptors
  119.  section.)
  120. N6The stream takes posession of the Apple Event data in 
  121. ; you can
  122. t use it
  123. NQdirectly until you close the stream. To ensure this, the descriptor pointed to by
  124. / parameter is cleared out to a null descriptor.
  125. Zapf Dingbats
  126. Warning
  127. )D<Do not open a stream on an Apple Event that is in use by the
  128. Apple Event Manager 
  129. $ the current event being handled, or
  130. Palatino
  131. The Apple Event Stream Library
  132. 20 March 1995
  133. Page 
  134. 9a pending reply 
  135.  or the AEM may become very unhappy with
  136. your meddling. 
  137. Zapf Dingbats
  138. AEStream_CreateEvent
  139. Courier
  140. OSErr AEStream_CreateEvent(
  141. %AEStreamRef, AEEventClass, AEEventID,
  142. ?DescType targetType, const void *targetData, long targetLength,
  143. $short returnID, long transactionID )
  144. AEStream_CreateEvent
  145.  first calls 
  146. AECreateAppleEvent
  147.  to create a new Apple
  148. f,event, then opens a stream on it by calling 
  149. AEStream_OpenEvent
  150. AEStream_Close
  151. 3OSErr AEStream_Close( AEStreamRef s, AEDesc *desc )
  152. AEStream_Close
  153.  closes the stream. If 
  154.  , the data in the stream will be
  155. fRdisposed with no questions asked. (Use this if you need to abort due to an error.)
  156. ;Otherwise, the finished descriptor will be copied into the 
  157. AEDesc
  158.  pointed to by
  159. 4. If the descriptor is not finished, the error code 
  160. errAEStream_BadNesting
  161.  will
  162. be returned.
  163. KIf you opened the stream on an Apple event, after the stream is closed the 
  164. f/parameter will contain a bona fide Apple event.
  165. 0After closing a stream, you can re-open it with 
  166. AEStream_Open
  167.  and re-use it 
  168. new data, of course.
  169. RITING 
  170. IMPLE 
  171. ESCRIPTORS
  172. fMThese routines let you write data descriptors to the stream. Do not use these
  173. Rroutines to write lists or records! You write those by using routines described in
  174. following sections.
  175. Palatino
  176. The Apple Event Stream Library
  177. Page 
  178. 20 March 1995
  179. AEStream_WriteDesc
  180. Courier
  181. ROSErr AEStream_WriteDesc( AEStreamRef s, DescType type, void *data, Size length );
  182. AEStream_WriteDesc
  183. )l6 appends an arbitrary block of data to the stream as a
  184. descriptor, much like 
  185. AECreateDesc
  186. AEPutPtr
  187. AEStream_WriteAEDesc
  188. :OSErr AEStream_WriteAEDesc( AEStreamRef s, AEDesc *desc );
  189. AEStream_WriteAEDesc
  190. )x4 appends a prepackaged Apple Event descriptor to the
  191. stream 
  192. , much like 
  193. )>    AEPutDesc
  194. . The descriptor 
  195.   is not disposed by the call; if
  196. N:you don
  197. t need it anymore, dispose it yourself by calling 
  198. AEDisposeDesc
  199. N9AEStream_OpenDesc, AEStream_WriteData, AEStream_CloseDesc
  200. 9OSErr AEStream_OpenDesc(  AEStreamRef s, DescType type );
  201. COSErr AEStream_WriteData( AEStreamRef s, void *data, Size length );
  202. *OSErr AEStream_CloseDesc( AEStreamRef s );
  203. *!OUse these three routines if you want to write a data descriptor piece by piece.
  204. First call 
  205. AEStream_OpenDesc
  206. , then call 
  207. AEStream_WriteData
  208.  zero or more times to
  209. N,write zero or more bytes of data, then call 
  210. AEStream_CloseDesc
  211.  to end the
  212. descriptor.
  213. Palatino
  214. The Apple Event Stream Library
  215. 20 March 1995
  216. Page 
  217. RITING 
  218. f%AEStream_OpenList, AEStream_CloseList
  219. Courier
  220. *OSErr AEStream_OpenList(  AEStreamRef s );
  221. *OSErr AEStream_CloseList( AEStreamRef s );
  222. To write a list, call 
  223. AEStream_OpenList
  224. )f(, write zero or more descriptors as list
  225. elements, then call 
  226. AEStream_CloseList
  227. )l%.  The descriptors can be simple data
  228. f7descriptors (see above), lists, or records (see below).
  229. RITING 
  230. ECORDS
  231. f)AEStream_OpenRecord, AEStream_CloseRecord
  232. ;OSErr AEStream_OpenRecord(  AEStreamRef s, DescType type );
  233. ,OSErr AEStream_CloseRecord( AEStreamRef s );
  234. To write a record, call 
  235. AEStream_OpenRecord
  236. , write zero or more 
  237. key descriptors
  238. (see below), then call 
  239. AEStream_CloseRecord
  240. AEStream_OpenRecord
  241. )r     lets you
  242. fHspecify the type to which the record should be coerced; use the constant
  243. typeAERecord
  244. )H! if you want an uncoerced record.
  245. AEStream_SetRecordType
  246. =OSErr AEStream_SetRecordType( AEStreamRef s, DescType type );
  247. Palatino
  248. The Apple Event Stream Library
  249. Page 
  250. 20 March 1995
  251. NNAt any time between opening a record and closing it, you can coerce the record
  252. to a different type by calling 
  253. Courier
  254. AEStream_SetRecordType
  255. . (This is useful if you don
  256. N?know what type to make the record until it
  257. s time to close it.)
  258. RITING 
  259. ESCRIPTORS 
  260. ECORDS
  261. NNUse these functions to add elements to records, and to add parameters to Apple
  262. events.
  263. AEStream_WriteKeyDesc
  264. :OSErr AEStream_WriteKeyDesc( AEStreamRef s, AEKeyword key,
  265. )DescType type, void *data, Size length );
  266. AEStream_WriteKeyDesc
  267. )~4 writes a complete key descriptor. It
  268. s identical to
  269. AEStream_WriteDesc
  270.  except for the 
  271. ) parameter which specifies the keyword to
  272. use for this descriptor.
  273. AEStream_OpenKeyDesc
  274. JOSErr AEStream_OpenKeyDesc( AEStreamRef s, AEKeyword key, DescType type );
  275. AEStream_OpenKeyDesc
  276.  is identical to 
  277. AEStream_OpenDesc
  278.  except for the 
  279. NEparameter which specifies the keyword to use for this descriptor. Use
  280. AEStream_CloseDesc
  281.  to end the descriptor.
  282. AEStream_WriteKey
  283. 8OSErr AEStream_WriteKey( AEStreamRef s, AEKeyword key );
  284. Palatino
  285. The Apple Event Stream Library
  286. 20 March 1995
  287. Page 
  288. Courier
  289. AEStream_WriteKey
  290. )f; writes the keyword to be used by the immediately following
  291. f3descriptor, list or record. The next AEStream call 
  292.  begin a descriptor 
  293. must be 
  294. _WriteDesc
  295.     _OpenDesc
  296.     _OpenList
  297. _OpenRecord
  298.  or you
  299. ll get a
  300. nesting error.
  301. AEStream_WriteKey
  302. )f@ is the only way to add a list or record as a field of a record.
  303. s also useful if you are writing a record and want to call a subroutine that
  304. writes a descriptor:
  305. *err= AEStream_OpenRecord(s, typeAERecord);
  306. "err= AEStream_WriteKey(s, kMyKey);
  307. // this is the key
  308. writeMyDescriptor(s);
  309. // for this descriptor
  310. err= AEStream_CloseRecord(s);
  311. AEStream_OptionalParameter
  312. AOSErr AEStream_OptionalParameter( AEStreamRef s, AEKeyword key );
  313. Call 
  314. AEStream_OptionalParameter
  315. / to specify that the Apple event parameter with
  316. fPthe given keyword is an optional parameter. (This means that the receiver of the
  317. .event is not required to read that parameter.)
  318. MThis function just adds the keyword to the optional-keywords attribute of the
  319. Mevent. You can call it before, during or after adding the matching parameter.
  320. @    >%^
  321. ('&:O
  322. p 0p`P
  323. xP(H`X
  324.     temp.0001
  325. N^ _\ON
  326. Jens Alfke
  327. Apple Computer
  328. Microsoft Word
  329. New York
  330. Zapf Dingbats
  331. Palatino
  332. Courier
  333. bPREC
  334. nPRVS
  335. zCAPN
  336.